home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / tools / czesc_1 / easyprocess / source / loop / loop.c < prev    next >
C/C++ Source or Header  |  1992-09-07  |  1KB  |  74 lines

  1. #include <arpbase.h>
  2. #include <arp_proto.h>
  3. #include "source:launch/Launch.h"
  4.  
  5.  
  6. void main (WORD argc, char *argv[]);
  7. void Reader (BPTR File[2]);
  8.  
  9.  
  10. struct ArpBase *ArpBase;
  11.  
  12. #define F_IN    0
  13. #define F_OUT    1
  14.  
  15. void main (WORD argc, char *argv[])
  16. {
  17.     struct Process *Proc1, *Proc2;
  18.     BPTR HC[2];
  19.     BPTR RAW[2];
  20.  
  21.     if (argc < 3)
  22.     {
  23.         puts ("Specify two file to link.\n\nFor example: Loop hc:1 \"raw:0/0/640/100/HC11 numer 1\"");
  24.         exit (5);
  25.     }
  26.  
  27.     ArpBase = (struct ArpBase *)OpenLibrary ("arp.library", 33L);
  28.     if (ArpBase)
  29.     {
  30.         RAW[F_OUT] = HC[F_IN] = Open (argv[1], MODE_NEWFILE);
  31.         if (HC[F_IN] && IsInteractive ( HC[F_IN] ))
  32.         {
  33.             RAW[F_IN] = HC[F_OUT] = Open (argv[2], MODE_NEWFILE);
  34.             if (HC[F_OUT] && IsInteractive(HC[F_OUT]))
  35.             {
  36.                 Proc1 = StartProcess ("HC Server", (CPTR)Reader, HC, 1);
  37.                 if (Proc1)
  38.                 {
  39.                     Proc2 = StartProcess ("RAW Server", (CPTR)Reader, RAW, 1);
  40.                     if (Proc2)
  41.                     {
  42.                         Wait (SIGBREAKF_CTRL_C);
  43.                         KillProcess (Proc2);
  44.                         Write (RAW[F_IN], (char *)" ", 1);
  45.                     }
  46.                     KillProcess (Proc1);
  47.                     Write (HC[F_IN], (char *)" ", 1);
  48.                     WaitProcesses ();
  49.                 }
  50.                 Close (HC[F_OUT]);
  51.             }
  52.             Close (HC[F_IN]);
  53.         }
  54.         CloseLibrary (ArpBase);
  55.     }
  56.     exit (0);
  57. }
  58.  
  59.  
  60. void Reader (BPTR File[2])
  61. {
  62.     ULONG Buffer;
  63.  
  64.     while (1)
  65.     {
  66.         Read (File[F_IN], &Buffer, 1);
  67.         Write (File[F_OUT], &Buffer, 1);
  68.         if (0 != CheckKill ())
  69.         {
  70.             return;
  71.         }
  72.     }
  73. }
  74.